<?php
namespace frontend\controllers;

use frontend\models\Comment;
use frontend\models\NewProject;
use common\components\FrontBaseController;
use frontend\models\PostsCollect;
use Yii;
use \common\helps\tools;
use \common\helps\code;
use yii\db\Query;

/**
 * Project controller
 */
class ProjectController extends FrontBaseController
{

    public $modelClass = 'frontend\models\NewProject';
    public function init()
    {
        parent::init();
    }

    /***首页项目推荐列表相关***/
    /**
     * 获取推荐项目列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetRecommendProjectList(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->queryParams;
        $total_data = $model->getProjectList($params);
        $data = tools::getPageData($total_data,empty($params['page_size'])?'':$params['page_size'],empty($params['page'])?'':$params['page']);

        return code::success($data);

    }



    /**
     * 获取项目详情
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectInfo(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if(empty($params['project_id'])){  return code::error('error','参数错误');}
        $list =$model->getProjectInfo($params,$this->member_info);
       return code::success($list);

    }

    /**
     * 获取是否收藏该项目
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetIsCollectProject(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if(empty($params['project_id'])){  return code::error('error','参数错误');}
        $list =$model->getICollectProject($params,$this->member_info);
        return code::success($list);

    }


    /**
     * 获取项目详情演职人员列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectActorInfo(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if(empty($params['project_id'])){  return code::error('error','参数错误');}
        $total_data =$model->getProjectActorInfo($params);
        $list = tools::getPageData($total_data,empty($params['page_size'])?'':$params['page_size'],empty($params['page'])?'':$params['page']);
        return code::success($list);

    }

    /**
     * 获取项目海报
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectBannerInfo(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if(empty($params['project_id'])){  return code::error('error','参数错误');}
        $total_data =$model->getProjectBannerInfo($params);
        $list = tools::getPageData($total_data,empty($params['page_size'])?'':$params['page_size'],empty($params['page'])?'':$params['page']);
        return code::success($list);

    }


    /**
     * 获取项目视频
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectVideoInfo(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if(empty($params['project_id'])){  return code::error('error','参数错误');}
        $total_data =$model->getProjectVideoInfo($params);
        $list = tools::getPageData($total_data,empty($params['page_size'])?'':$params['page_size'],empty($params['page'])?'':$params['page']);
        return code::success($list);

    }

    /**
     * 获取项目动态
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectInformationInfo(){
        $request = $this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        if (empty($params['project_id'])) {
            return code::error('error', '参数错误');
        }
        $total_data = $model->getProjectInformationInfo($params);
        $list = tools::getPageData($total_data, empty($params['page_size']) ? '' : $params['page_size'], empty($params['page']) ? '' : $params['page']);
        return code::success($list);
    }



    /**
     * 获取项目相关帖子列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectPostsList(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->bodyParams;
        $params['member_id'] = empty($this->member_info['id'])?'':$this->member_info['id'];
        if (empty($params['project_id'])) {
            return code::error('error', '参数错误');
        }
        $list = $model->getProjectPostsList($params);
        return code::success($list);

    }




     /**
     * 获取项目电影总分类列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetIndexProjectInfo(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->queryParams;
        $list =$model->getIndexProjectInfo($params);
        return code::success($list);

    }

    /**
     * 获取某分类项目电影列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetTargetProjectList(){
        $request =$this->request;
        $model = new NewProject();
        $params = $request->queryParams;
        $total_data =$model->getTargetProjectList($params);
        $list = tools::getPageData($total_data, empty($params['page_size']) ? '' : $params['page_size'], empty($params['page']) ? '' : $params['page']);
        return code::success($list);

    }

    /**
     * 获取项目分类列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetProjectClassList(){
        $model = new NewProject();
        $total_data =$model->getProjectClassList();
        $list = tools::getPageData($total_data, empty($params['page_size']) ? '' : $params['page_size'], empty($params['page']) ? '' : $params['page']);
        return code::success($list);

    }


    /**
     * 取消收藏与收藏项目
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionProjectCollect(){
        $request =$this->request;
        $model = new PostsCollect();
        $params = $request->bodyParams;
        $params['member_id']=$this->member_info['id'];
        if(!empty($params['is_collect']) && $params['is_collect']==2){ //取消收藏
            $model->scenario='update_project';
        }elseif(!empty($params['is_collect']) && $params['is_collect']==1){
            $model->scenario='create_project';
        }else{
            return code::error('error','参数错误');
        }
        $model->load($params,'');
        if(!$model->validate()){
            $error = array_values($model->getErrors());
            return code::error('',$error[0][0]);
        }
        $data =$model->projectCollect($params);
        if(!empty($data['error'])){
            return code::error('error',$data['error']);
        }else{
            return code::success();
        }

    }


    /**
     * 获取首页搜索结果列表
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetIndexSearchList(){
        $request =$this->request;
        $params = $request->bodyParams;
        $model = new NewProject();
        $total_data =$model->getIndexSearchList($params,$this->member_info);
        $list = tools::getPageData($total_data, empty($params['page_size']) ? '' : $params['page_size'], empty($params['page']) ? '' : $params['page']);
        return code::success($list);

    }


    /**
     * 获取当前会员是否有权限加入群组
     * @author hey_heyang(635870453@qq.com)
     * @return json
     */
    public  function  actionGetAllowedJoinGroup(){
        $request =$this->request;
        $params = $request->bodyParams;
        $model = new NewProject();
        if(empty($params['group_id'])) return code::error('error','参数错误!');
        $data =$model->getAuthJoinGroup($params,$this->member_info);
        if(!empty($data['error'])) return code::error('error',$data['error']);
        return code::success($data);

    }











}
